using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using CommonLibrary.DBUtility;
using CommonLibrary.Model;

namespace CommonLibrary.DAL
{
    public class LinkmanGroup
    {
        public bool Exsits(int LinkmanGroupID)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroupID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "LinkmanGroup_Exsits", parameters);
                if (dr.Read())
                    return true;
                else
                    return false;
            }
        }
        public bool Insert(LinkmanGroupInfo LinkmanGroup)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupNO",SqlDbType.Int),
                new SqlParameter("@LinkmanID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroup.LinkmanGroupNO;
            parameters[1].Value = LinkmanGroup.LinkmanID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "LinkmanGroup_Insert", parameters);
                return rowAffected > 0;
            }
        }
        public bool Update(LinkmanGroupInfo LinkmanGroup)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupNO",SqlDbType.Int),
                new SqlParameter("@LinkmanID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroup.LinkmanGroupNO;
            parameters[1].Value = LinkmanGroup.LinkmanID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "LinkmanGroup_Update", parameters);
                return rowAffected > 0;
            }
        }
        public bool Delete(int LinkmanGroupID)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroupID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "LinkmanGroup_Delete", parameters);
                return rowAffected > 0;
            }
        }
        public bool DeleteByLinkmanGroupNo(int LinkmanGroupNo)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupNo",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroupNo;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "LinkmanGroup_DeleteByLinkmanGroupNo", parameters);
                return rowAffected > 0;
            }
        }
        public bool DeleteByLinkmanID(int LinkmanID)
        {
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                int rowAffected = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "LinkmanGroup_DeleteByLinkmanID", parameters);
                return rowAffected > 0;
            }
        }
        public LinkmanGroupInfo GetLinkmanGroup(int LinkmanGroupID)
        {
            LinkmanGroupInfo LinkmanGroup = null;
            SqlParameter[] parameters = {
                new SqlParameter("@LinkmanGroupID",SqlDbType.Int)
            };
            parameters[0].Value = LinkmanGroupID;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "LinkmanGroup_GetDetail", parameters);
                if (dr.Read())
                {
                    LinkmanGroup = new LinkmanGroupInfo();
                    LinkmanGroup.LinkmanGroupID = dr.GetInt32(0);
                    LinkmanGroup.LinkmanGroupNO = dr.GetInt32(1);
                    LinkmanGroup.LinkmanID = dr.GetInt32(2);
                }
                return LinkmanGroup;
            }
        }
        public List<LinkmanGroupInfo> GetList(string StrWhere)
        {
            List<LinkmanGroupInfo> LinkmanGroups = new List<LinkmanGroupInfo>();
            LinkmanGroupInfo LinkmanGroup = null;
            SqlParameter[] parameters = {
                new SqlParameter("@StrWhere",SqlDbType.NVarChar,4000)
            };
            parameters[0].Value = StrWhere;
            using (SqlConnection conn = new SqlConnection(SqlHelper.CONN_STRING))
            {
                SqlDataReader dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "LinkmanGroup_GetList", parameters);
                while (dr.Read())
                {
                    LinkmanGroup = new LinkmanGroupInfo();
                    LinkmanGroup.LinkmanGroupID = dr.GetInt32(0);
                    LinkmanGroup.LinkmanGroupNO = dr.GetInt32(1);
                    LinkmanGroup.LinkmanID = dr.GetInt32(2);
                    LinkmanGroups.Add(LinkmanGroup);
                }
                return LinkmanGroups;
            }
        }

    }
}